import numpy as np
import torch
import random
import math
import torch.nn.functional as F
import matplotlib.pyplot as plt
import re
import torch.nn as nn

m = nn.Conv2d(3, 6, 1, stride=1)  # 输入通道数3，输出通道数3即核数为3
# m = nn.Conv2d(3, 6, 1, stride=2)  #
# m = nn.Conv2d(3, 6, 2, stride=1)  #
# 将以上三个分别解开，看结果，会发现weight确实是和通道数一致的：输入通道是3，卷积核6个，
# 因为每个卷积核要和每个通道进行一次卷积计算所以需要一个weight 所以是3*6
# 经试验发现 weight当中的另外两个1和卷积核大小有关和步长没关系，bias为啥是6，因为6个卷积核，
# 就需要6个偏置
a = torch.ones(1*3*6*6).reshape(1, 3, 6, 6)  # 第二列的3代表输入通道数 这个数字一定要和Conv2d一致
result = m(a)
print('result.shape\n', result.shape)
print(m.parameters())
# print("*"*100)
for i in m.parameters():
    print(i.numel())
    print('name', i.name, "\nshape", i.shape)
print("*"*100)
print('weight\n', m.weight, '\nshape\n', m.weight.shape)
print('bias\n', m.bias, '\nshape\n', m.bias.shape)
